﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}

<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <input id="id" type="hidden" name="id" />
        <div class="form-group">
            <label class="col-sm-3 control-label ">上级菜单</label>
            <div class="col-sm-8">
                <input id="parentId" type="hidden" name="ParentId" />
                <input id="parentName" name="parentName" type="text" class="form-control" readonly="readonly" onclick="showChooseForm()" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">菜单类型</label>
            <div class="col-sm-8" id="menuType" name="menuType"></div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">菜单名称<font class="red"> *</font></label>
            <div class="col-sm-8">
                <input id="menuName" name="menuName" type="text" class="form-control" autocomplete="off" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">权限标识</label>
            <div class="col-sm-8">
                <input id="authorize" name="authorize" type="text" class="form-control" autocomplete="off" />
                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 控制器中定义的权限标识，如：system:menu:search</span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">请求地址</label>
            <div class="col-sm-8">
                <input id="menuUrl" name="menuUrl" type="text" class="form-control" autocomplete="off" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">显示排序</label>
            <div class="col-sm-8">
                <input id="menuSort" name="menuSort" type="text" class="form-control" autocomplete="off" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">图标</label>
            <div class="col-sm-8">
                <input id="menuIcon" name="menuIcon" class="form-control" type="text" placeholder="选择图标">
                <div class="ms-parent" style="width: 100%;">
                    <div class="icon-drop animated flipInX" style="display: none;max-height:200px;overflow-y:auto">
                        @Html.PartialAsync("MenuIcon").Result
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">菜单状态</label>
            <div class="col-sm-8" id="menuStatus" name="menuStatus"></div>
        </div>
    </form>
</div>

<script type="text/javascript">

    $(function () {

        $("#menuType").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(MenuTypeEnum).EnumToDictionaryString())) });
          //加载用户状态
        $("#menuStatus").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(StatusEnum).EnumToDictionaryString())) });
        //选择图标
        $("#menuIcon").focus(function () {
            $(".icon-drop").show();
        });
        $(".icon-drop").find(".ico-list i").on("click", function () {
            $('#menuIcon').val($(this).attr('class'));
            $(".icon-drop").hide();
        });
        //显示隐藏
        $('input[name=menuType_radiobox]').on('ifChecked', function (event) {
            var menuType = $(event.target).val();
            menuVisible(menuType);
        });
        $("#form").validate({
            rules: {
                menuName: { required: true }
            }
        });
        getForm();
    });

    function menuVisible(menuType) {
        if (menuType == "@MenuTypeEnum.Directory.ParseToInt()") {
            $("#menuUrl").parents(".form-group").hide();
            $("#authorize").parents(".form-group").hide();
            $("#menuIcon").parents(".form-group").show();
        } else if (menuType == "@MenuTypeEnum.Menu.ParseToInt()") {
            $("#menuUrl").parents(".form-group").show();
            $("#authorize").parents(".form-group").show();
            $("#menuIcon").parents(".form-group").hide();
        } else if (menuType == "@MenuTypeEnum.Button.ParseToInt()") {
            $("#menuUrl").parents(".form-group").hide();
            $("#authorize").parents(".form-group").show();
            $("#menuIcon").parents(".form-group").hide();
        }
    }
    function getForm() {
        //修改赋值使用
        var editData = storage.get("editData");
        if (editData != null && editData.length > 0) {
            var data = JSON.parse(editData);
            //表单赋值
            $("#form").setWebControls(data);
            $('#menuTree').ysTree("setCheckedNodes", data.menuIds);
        } else {
            //界面初始化 给状态、性别赋值
           var defaultData = {};
           defaultData.parentId = 0;
           defaultData.parentName = "主目录";
           defaultData.menuStatus = 1;
           defaultData.menuType = 1;
           defaultData.menuStatus = "@StatusEnum.Yes.ParseToInt()";
           $("#form").setWebControls(defaultData);
        }
    }

    //提交数据
    function submitForm(index) {
        if ($("#form").validate().form()) {
            var postData = $("#form").getWebControls();
            $.operate.save("/SystemManage/Menu/SaveFormJson", postData);
        }
    }
    //树形选择菜单
    function showChooseForm() {
        var treeId = $("#treeId").val();
        var menuId = treeId > 0 ? treeId : 1;
        var url ="/SystemManage/Menu/MenuChoose";
        var options = {
            title: '菜单选择',
            width: "380",
            url: url,
            callBack: function (index, layero) {
                var body = layer.getChildFrame('body', index);
                $("#parentId").val(body.find('#treeId').val());
                $("#parentName").val(body.find('#treeName').val());
                layer.close(index);
            }
        };
        $.modal.openOptions(options);
    }
</script>
